import { INJECTEDTOKENS } from "@nestjs/constant";
import "reflect-metadata";

export function Inject(token: string): ParameterDecorator {
  // target 代表类本身 propertyKey 代表类的方法名 parameterIndex 代表参数的下标
  return (target: Object, propertyKey: string | symbol, parameterIndex: number) => {
    const existingInjectedTokens = Reflect.getMetadata(INJECTEDTOKENS, target, propertyKey) || [];
    existingInjectedTokens[parameterIndex] = token;
    Reflect.defineMetadata(INJECTEDTOKENS, existingInjectedTokens, target);
  };
}
